﻿using MuPDFCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using PixelFormats = MuPDFCore.PixelFormats;

namespace BookViewer
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            MuPDFCore.MuPDFRenderer.PDFRenderer render = new MuPDFCore.MuPDFRenderer.PDFRenderer();
        }

        private void OnButtonOpenFileClick(object sender, RoutedEventArgs e)
        {
            //var pdf = new MuPDFCore.MuPDFDocument();
            //Initialise the MuPDF context. This is needed to open or create documents.
            using MuPDFContext ctx = new MuPDFContext();
            //Open a PDF document
            using MuPDFDocument document = new MuPDFDocument(ctx, "path/to/document.pdf");
            //Page index (page 0 is the first page of the document)
            int pageIndex = 0;
            //Zoom level, converting document units into pixels. For a PDF document, a 1x zoom level corresponds to a
            //72dpi resolution.
            double zoomLevel = 1;
            //Save the first page as a PNG image with transparency, at a 1x zoom level (1pt = 1px).
            document.SaveImage(pageIndex, zoomLevel, PixelFormats.RGBA, "path/to/output.png",
            RasterOutputFileTypes.PNG);
        }
    }
}
